package com.example.yls.demoa;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.RequiresApi;
import android.util.Log;

public class MyService extends Service {
    public MyService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }


    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onCreate() {
        super.onCreate();
        Log.e("MyService","thread id="+Thread.currentThread().getId());

        Intent intent=new Intent(MyService.this,TianqiActivity.class);
        PendingIntent pi=PendingIntent.getActivities(MyService.this,1001,
                new Intent[]{intent},0);

        Bitmap tianqi= BitmapFactory.decodeResource(getResources(),R.drawable.tianqi);
        Notification notification=new Notification.Builder(MyService.this)
                .setContentTitle("通知标题")
                .setContentText("通知内容")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(tianqi)
                .setContentIntent(pi)
                .build();

        startForeground(1,notification);

       /* new Thread(new Runnable() {
            @Override
            public void run() {
                int i=0;
                while (i<20){
                    Log.e("MyService","i="+i);
                    i++;

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();*/

    }

}
